﻿@page
@model FytSoa.Web.Pages.FytAdmin.Sys.AdminModifyModel
@{
    ViewData["Title"] = "编辑/添加用户";
    Layout = "~/Pages/FytAdmin/_Layout.cshtml";
}
<style>
    .organize-tree {
        position: absolute;
        background-color: #fff;
        padding: 5px 25px;
        z-index: 1000;
        box-shadow: 0 0 24px rgba(0,0,0,.18);
        opacity: 0;
        height: 0;
        display: none;
    }

        .organize-tree.active {
            display: block;
            opacity: 1;
            height: auto;
            max-height: 500px;
            overflow: auto;
            transition: all .5s;
        }
</style>
<form class="layui-form form-cus" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">所属部门</label>
        <div class="layui-input-block">
            <input type="text" name="DepartmentName" id="DepartmentName" value="@Model.adminModel.DepartmentName" lay-verify="required" lay-verType="tips" autocomplete="off" placeholder="请选择所属部门" class="layui-input">
            <div class="organize-tree">
                <div id="tree" class="layui-tree-cus"></div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">登录账号</label>
            <div class="layui-input-inline">
                <input type="text" name="LoginName" value="@Model.adminModel.LoginName" maxlength="20" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">登录密码</label>
            <div class="layui-input-inline">
                <input type="password" name="LoginPwd" value="@Model.adminModel.LoginPwd" maxlength="20" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-inline">
                <input type="text" name="TrueName" value="@Model.adminModel.TrueName" maxlength="10" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">编号</label>
            <div class="layui-input-inline">
                <input type="text" name="Number" value="@Model.adminModel.Number" maxlength="6" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-inline">
                <input type="radio" name="Sex" value="男" title="男" @(Model.adminModel.Sex == "男" ? "checked" : "")>
                <input type="radio" name="Sex" value="女" title="女" @(Model.adminModel.Sex == "女" ? "checked" : "")>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <input type="checkbox" @(Model.adminModel.Status ? "checked" : "") name="Status" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">手机号码</label>
            <div class="layui-input-inline">
                <input type="text" name="Mobile" value="@Model.adminModel.Mobile" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="email" name="Email" value="@Model.adminModel.Email" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-cur-submit">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="submit" id="submit"><i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop layui-hide"></i>立即提交</button>
            <button type="button" class="layui-btn layui-btn-primary btn-open-close">取消</button>
        </div>
    </div>    
    <input type="hidden" name="Guid" id="Guid" value="@Model.adminModel.Guid" />
    <input type="hidden" name="DepartmentGuid" id="DepartmentGuid" value="@Model.adminModel.DepartmentGuid" />
</form>
@section Scripts{
<script>layui.config({
        base: '/themes/js/modules/'
    }).use(['layer', 'jquery', 'common', 'form', 'tree'], function () {
        var form = layui.form, $ = layui.$, os = layui.common, tree = layui.tree;
        var index = parent.layer.getFrameIndex(window.name);
        //监听提交
        form.on('submit(submit)', function (data) {
            $('#submit').attr('disabled', true).find('i').removeClass('layui-hide');
            var urls = "api/admin/add";
            if ($("#Guid").val()) {
                urls = "api/admin/edit";
            }
            data.field.Status = data.field.Status === 'on' ? true : false;
            os.ajax(urls, data.field, function (res) {
                $('#submit').attr('disabled', false).find('i').addClass('layui-hide');
                if (res.statusCode == 200) {
                    parent.layer.close(index);
                }
                else {
                    os.error(res.message);
                }
            });
            return false;
        });
        $(".btn-open-close").on('click', function () {
            parent.layer.close(index);
        });

        os.ajax('api/organize/gettree/', {}, function (res) {
            console.log(res);
            tree.render({
                elem: '#tree'
                , data: res
                , onlyIconControl: true
                , click: function (obj) {
                    guid = obj.data.id;
                    $("#DepartmentGuid").val(obj.data.id);
                    $("#DepartmentName").val(obj.data.title);
                    $(".organize-tree").removeClass('active');
                }
            });
        });
        $("#DepartmentName").click(function () {
            $(".organize-tree").addClass('active');
        });
        $(".organize-tree").mouseleave(function () {
            $(".organize-tree").removeClass('active');
        });
    });</script>
}

